package ch.bfh.abcmmh.view.detailview.minipanels;


import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.Observable;
import java.util.Observer;

import javax.swing.JLabel;
import javax.swing.JPanel;

import ch.bfh.abcmmh.view.detailview.streets.StreetPanel;

public class SpeedLimitPanelMouseListener extends JPanel implements Observer{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	int radius=50;
	int speedlimit;
	int xOffset;
	JLabel label;
	bigCircle bigC;
	miniCircle miniC;
	StreetPanel streetPanel;
	

	
	
	public SpeedLimitPanelMouseListener(int speedLimit, StreetPanel streetPanel){
		this.streetPanel=streetPanel;
		this.speedlimit=speedLimit;
		bigC= new bigCircle();
		miniC = new miniCircle();
		this.label=new JLabel(Integer.toString(speedLimit));
		label.setOpaque(false);
		label.setLayout(null);
		label.setBackground(Color.black);
	    Dimension size = new Dimension(50,50);
	    setPreferredSize(size);
	    setMinimumSize(size);
	    setMaximumSize(size);
	    setSize(size);
	    setLayout(null);
	    this.addMouseListener(new MouseEventsListener());
	    this.setOpaque(false);
	    miniC.add(label);
	    this.add(bigC);
	    bigC.add(miniC);
	    streetPanel.getLogicController().getClock().addObserver(this);
	   
	    

	   
	   
	}

	 class miniCircle extends JPanel{
		 
		 /**
		 * 
		 */
		private static final long serialVersionUID = 1L;
		miniCircle(){
			    Dimension size = new Dimension(40,40); 
			    setPreferredSize(size);
			    setMinimumSize(size);
			    setMaximumSize(size);
			    setSize(size);
			    this.setOpaque(false);
			    this.addMouseListener(new MouseEventsListener());
			 
		 }
		 public void paintComponent(Graphics g) {
		    
		        g.setColor(Color.white);
		        g.fillRoundRect(0,0, getWidth()-1, getHeight()-1, radius, radius);
		   
		   }
	}
	 
	 class bigCircle extends JPanel{
		 /**
		 * 
		 */
		private static final long serialVersionUID = 1L;
		public bigCircle(){
			    Dimension size = new Dimension(50,50); 
			    setPreferredSize(size);
			    setMinimumSize(size);
			    setMaximumSize(size);
			    setSize(size);
			    
			    this.setOpaque(false);
			    this.addMouseListener(new MouseEventsListener());
		 }
		 public void paintComponent(Graphics g) {
		      
		        g.setColor(Color.red);
		        g.fillRoundRect(0,0, getWidth()-1, getHeight()-1, radius, radius);
		        
		   }
	}
	 class MouseEventsListener implements MouseListener{

		@Override
		public void mouseClicked(MouseEvent e) {
			// TODO Auto-generated method stub
			
		}

		@Override
		public void mouseEntered(MouseEvent e) {
			// TODO Auto-generated method stub
			
		}

		@Override
		public void mouseExited(MouseEvent e) {
			// TODO Auto-generated method stub
			
		}

		@Override
		public void mousePressed(MouseEvent e) {
			// TODO Auto-generated method stub
			
		}

		@Override
		public void mouseReleased(MouseEvent e) {
			int offset=streetPanel.getStreetController().getCurrentPos();
			streetPanel.addSpeedLimit(speedlimit, e.getX()+ offset);
			streetPanel.getLogicController().getStreetGenerator().setSpeedLimit(e.getX()+ offset, speedlimit);
			streetPanel.getGUIController().getMainFrame().getFullviewPanel().updateAllStreetSequences();
	
			
		}
		 
	 }
	@Override
	public void update(Observable arg0, Object arg1) {
		//this.setLocation(9999999, 0);
		//streetPanel.getLogicController().getClock().deleteObserver(this);
		
		
		
	}

}
